/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * EditPostPanel1.java
 *
 * Created on 26/04/2011, 21:24:43
 */

package presentation.gui;
 import domain.ClientController;

/**
 *
 * @author yedidim
 */
public class EditPostPanel extends javax.swing.JPanel {
private ClientController _clientController;
private String _forum_id;
private String _thread_id;
private String _postId;
 private  StartWindow _start;

   public EditPostPanel(ClientController clientController, String forum_id,
                                                        String thread_id,String PostId,String title1, String body1, StartWindow start) {
        this._clientController=clientController;
        this._forum_id=forum_id;
        this._thread_id=thread_id;
        this._postId=PostId;
        this._start=start;
        initComponents();
        title.setText(title1);
        body.setText(body1);
        setVisible(true);
    }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLayeredPane1 = new javax.swing.JLayeredPane();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        title = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        ok = new javax.swing.JButton();
        cancel = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        body = new javax.swing.JTextArea();

        jLayeredPane1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Forum System", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Kristen ITC", 1, 14), new java.awt.Color(255, 255, 255))); // NOI18N

        jLabel1.setFont(new java.awt.Font("Kristen ITC", 1, 14));
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("Please edit your post");
        jLabel1.setBounds(310, 40, 165, 20);
        jLayeredPane1.add(jLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel3.setFont(new java.awt.Font("Kristen ITC", 1, 14)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(255, 255, 255));
        jLabel3.setText("Body");
        jLabel3.setBounds(110, 130, 40, 20);
        jLayeredPane1.add(jLabel3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        title.setFont(new java.awt.Font("Kristen ITC", 1, 14)); // NOI18N
        title.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                titleActionPerformed(evt);
            }
        });
        title.setBounds(180, 80, 380, 30);
        jLayeredPane1.add(title, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel2.setFont(new java.awt.Font("Kristen ITC", 1, 14)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("Title");
        jLabel2.setBounds(110, 70, 40, 30);
        jLayeredPane1.add(jLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        ok.setFont(new java.awt.Font("Kristen ITC", 1, 14)); // NOI18N
        ok.setIcon(new javax.swing.ImageIcon(getClass().getResource("/presentation/gui/pics/Ok-icon.png"))); // NOI18N
        ok.setText("Ok");
        ok.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okActionPerformed(evt);
            }
        });
        ok.setBounds(220, 410, 130, 33);
        jLayeredPane1.add(ok, javax.swing.JLayeredPane.DEFAULT_LAYER);

        cancel.setFont(new java.awt.Font("Kristen ITC", 1, 14)); // NOI18N
        cancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/presentation/gui/pics/Close-icon.png"))); // NOI18N
        cancel.setText("Cancel");
        cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelActionPerformed(evt);
            }
        });
        cancel.setBounds(400, 410, 130, 33);
        jLayeredPane1.add(cancel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        body.setColumns(20);
        body.setFont(new java.awt.Font("Kristen ITC", 1, 14)); // NOI18N
        body.setRows(5);
        jScrollPane1.setViewportView(body);

        jScrollPane1.setBounds(180, 140, 380, 240);
        jLayeredPane1.add(jScrollPane1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLayeredPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 715, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(121, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLayeredPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 545, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void titleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_titleActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_titleActionPerformed

    private void okActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okActionPerformed
        String new_title=title.getText();
        String new_body=body.getText();
        //updating the database via the clientController
        this.getController().editPost(this.getForumId(), new_title, new_body,
                this.getThreadId(), this.getPostId());
        //shows the new post list
        getStart().getForum().displayForum( new PostsViewPanel(this._clientController,this._forum_id,this._thread_id,this.getStart() ) );
        //removig the view of new post
        this.setVisible(false);
}//GEN-LAST:event_okActionPerformed

    private void cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelActionPerformed
        getStart().getForum().displayForum( new PostsViewPanel(this._clientController,this._forum_id,this._thread_id,this.getStart()));
        this.setVisible(false);
}//GEN-LAST:event_cancelActionPerformed

    public ClientController getController(){
     return this._clientController;
 }

public String  getForumId(){
     return this._forum_id;
 }

 public String  getThreadId(){
     return this._thread_id;
 }

 public String  getPostId(){
     return this._postId;
 }

 public  StartWindow getStart(){
         return this._start;
     }
    /**
    * @param args the command line arguments
    */
 /*   public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new EditPostPanel().setVisible(true);
            }
        });
    }*/

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextArea body;
    private javax.swing.JButton cancel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLayeredPane jLayeredPane1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton ok;
    private javax.swing.JTextField title;
    // End of variables declaration//GEN-END:variables

}
